require('../../assets/css/index.less')
require('../../assets/fonts/iconfont.css')
require('../../lib/weui/weui.css');
require('./sport.less')
let weui = require('../../lib/weui/weui.js');

const dom = require('../../utils/dom');
const https = require('../../utils/https');
const local = require('../../utils/local');
let div = dom.getes('div')
dom.ready(function() {
    dom.bMenu("sport")
    let li = dom.getes("header ul li");
    let div = dom.getes("main>div")
    console.log(li, div);
    li.forEach((v, x) => {
        v.addEventListener("click", function() {
            div.forEach((v, x) => {
                v.style.display = 'none';
                li[x].classList.remove('active')
            });
            li[x].classList.remove('active');
            div[x].style.display = 'block';
            v.classList.add("active");
        })
    });



    https.get("/api/train/courseList", function(res) {
        console.log(res);
        let { errno, data } = res;
        let ne = data.filter(v => v.courseId == 1);
        console.log(ne);
        getcour("#ol", ne)
        let course = data.filter(v => v.courseId > 1);
        console.log(course);
        getcour("#ul", course)
    })


    function getcour(obj, data) {
        let html = ''
        data.map(v => {

            html += ` <a href="training.html?id=${v.courseId}"><li><img src="http://fitness.h5.itsource.cn:3701${v.imgurl
        }" alt="">
        <aside>
            <h2>${v.name}</h2>
            <p>${v.desc}</p>
        </aside></li></a>`
        });
        dom.gete(obj).innerHTML = html;
    }
})